{include file='public/_meta'}
    <title>新增订单</title>
</head>
<body>
<article class="page-container">
    <form class="form form-horizontal" id="form-admin-add" method="post" action="{:url('admin/qtgl/adddjdo')}">
        <table class="table table-border table-bordered radius">
            <tbody>
            <!---->
            <tr>
                <td>登记日期：<span class="c-red">*</span></td>
                <td>
                    <input type="text" onfocus="WdatePicker({ dateFmt:'yyyy-MM-dd HH:mm' })" id="djrq" name="djrq" value="{$djrq}" class="input-text Wdate  radius size-S"  required>
                </td>
                <td>值  班  人：<span class="c-red">*</span></td>
                <td>
                    <span class="select-box radius size-S">
                    <select class="select valid" size="1" name="zbr" id="zbr" title="请选择值班人" required>
                        <option value="">请选择值班人</option>
                        {foreach $zbr as $k=>$v}
                        <option value="{$v.title}">{$v.title}</option>
                        {/foreach}
                    </select>
                    </span>
                </td>
                <td>司       仪：<span class="c-red"></span></td>
                <td>
                    <span class="select-box radius size-S" aria-required="true">
                    <select name="sy" id="sy" class="select">
                        <option value="">请选择司仪</option>
                        {foreach $sy as $k=>$v}
                        <option value="{$v.title}">{$v.title}</option>
                        {/foreach}
                    </select>
                    </span>
                </td>
                <td>逝者姓名：<span class="c-red">*</span></td>
                <td>
                    <input type="text" name="xm" id="xm" class="input-text radius size-S"  required>
                </td>
            </tr>
            <tr>

                <td>性别：<span class="c-red">*</span></td>
                <td>
                    <input type="text" name="xb" id="xb" class="input-text radius size-S" required>
                </td>
                <td>年龄：<span class="c-red">*</span></td>
                <td>
                    <input type="text" name="nl" id="nl" class="input-text radius size-S" required isIntGtZero>
                </td>
                <td>民       族：<span class="c-red">*</span></td>
                <td>
                    <input type="text" name="mz" id="mz" class="input-text radius size-S" required>
                </td>
                <td>国家或地区：<span class="c-red">*</span></td>
                <td>
                    <input type="text" name="gjhdq" id="gjhdq" value="中国" class="input-text radius size-S" required>
                </td>

            </tr>
            <tr>

                <td>身份证类型：<span class="c-red">*</span></td>
                <td>
                    <input type="text" name="sfzlx" id="sfzlxnl" value="身份证" class="input-text radius size-S" required>
                </td>
                <td>证件号码：<span class="c-red">*</span></td>
                <td>
                    <input type="text" name="sfzh" id="sfzh" class="input-text radius size-S" required isIdCardNo>
                </td>
                <td>常住地址：<span class="c-red">*</span></td>
                <td colspan="3">
                    <input type="text" name="jtzz" id="jtzz" class="input-text radius size-S" required>
                </td>

            </tr>
            <tr>

                <td>死亡原因：<span class="c-red">*</span></td>
                <td>
                    <span class="select-box radius size-S">
                    <select name="swyy" id="swyy" class="select" required>
                        <option value="">请选择死亡原因</option>
                        {foreach $swyy as $k=>$v}
                        <option value="{$v.title}">{$v.title}</option>
                        {/foreach}
                    </select>
                    </span>
                </td>
                <td>证       件：<span class="c-red">*</span></td>
                <td>
                    <span class="select-box radius size-S">
                    <select name="zj" id="zj" class="select" required>
                        <option value="">请选择证件</option>
                        {foreach $zj as $k=>$v}
                        <option value="{$v.title}">{$v.title}</option>
                        {/foreach}
                    </select>
                    </span>
                </td>
                <td>死亡日期：<span class="c-red">*</span></td>
                <td>
                    <input type="text" onfocus="WdatePicker({ dateFmt:'yyyy-MM-dd' })" id="swrq" name="swrq" value="{$swrq}" class="input-text Wdate  radius size-S" required>
                </td>
                <td>减免类型：<span class="c-red"></span></td>
                <td>
                    <span class="select-box radius size-S">
                    <select name="jmlx" id="jmlx" class="select">
                        <option value="">请选择减免类型</option>
                        {foreach $jmlx as $k=>$v}
                        <option value="{$v.title}">{$v.title}</option>
                        {/foreach}
                    </select>
                    </span>
                </td>
            </tr>
            <tr>

                <td>户口所在地：<span class="c-red">*</span></td>
                <td colspan="3">
                    <input type="text" name="kkszd" id="kkszd" class="input-text radius size-S" required>
                </td>
                <td>是否本地户口：<span class="c-red">*</span></td>
                <td>
                    <span class="select-box radius size-S">
                    <select name="is_bdhk" id="is_bdhk" class="select" required>
                        <option value="">是否本地户口</option>
                        <option value="1">是</option>
                        <option value="0">否</option>
                    </select>
                    </span>
                </td>
                <td colspan="2">
                    <button id="readsfzBtn" name="readsfzBtn" class="btn btn-primary radius size-S">读取逝者信息</button>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <button id="readlxrsfzBtn" name="readlxrsfzBtn" class="btn btn-secondary radius size-S">读取经办人信息</button>
                </td>
            </tr>
            <tr><td colspan="8"></td></tr>
            <tr>
                <td>与逝者关系：<span class="c-red"></span></td>
                <td>
                    <span class="select-box radius size-S">
                    <select name="yszgx" id="yszgx" class="select">
                        <option value="">请选择与逝者关系</option>
                        {foreach $yszgx as $k=>$v}
                        <option value="{$v.title}">{$v.title}</option>
                        {/foreach}
                    </select>
                    </span>
                </td>
                <td>经办人姓名：<span class="c-red"></span></td>
                <td>
                    <input type="text" name="lxr" id="lxr" class="input-text radius size-S">
                </td>
                <td>联系电话：<span class="c-red"></span></td>
                <td>
                    <input type="text" name="lxdh" id="lxdh" class="input-text radius size-S" isTel>
                </td>
                <td>经办人身份证：<span class="c-red"></span></td>
                <td  colspan="3">
                    <input type="text" name="lxrsfz" id="lxrsfz" class="input-text radius size-S" isIdCardNo>
                </td>
            </tr>
            <tr><td colspan="8"></td></tr>
            <tr>
                <td>备注：<span class="c-red"></span></td>
                <td  colspan="3">
                    <textarea class="textarea radius size-S" style="height: 50px;" name="bz" id="bz" ></textarea>
                </td>
                <td>前台附加：<span class="c-red"></span></td>
                <td  colspan="3">
                    <textarea class="textarea radius size-S" style="height: 50px;" name="qtfj" id="qtfj" ></textarea>
                </td>
            </tr>
            <tr><td colspan="8"></td></tr>
            <tr>
                <td>遗体运送方式：<span class="c-red">*</span></td>
                <td colspan="3">
                    <span class="select-box radius size-S">
                    <select name="ytysfs" id="ytysfs" class="select" required>
                        <option value="">请选择遗体运送方式</option>
                        {foreach $ytysfs as $k=>$v}
                        <option value="{$v.title}">{$v.title}</option>
                        {/foreach}
                    </select>
                    </span>
                </td>
                <td>接尸费用：</td>
                <td colspan="3">
                    <input type="text" name="jsfy"  id="jsfy" class="input-text radius size-S">
                </td>
            </tr>
            <tr><td colspan="8"></td></tr>
            <tr>
                <td>是否存尸：<span class="c-red">*</span></td>
                <td>
                    <span class="select-box radius size-S">
                    <select name="is_cs" id="is_cs" class="select" required onchange="return isCs_Btn_onclick(this);">
                        <option value="">是否存尸</option>
                        <option value="1">是</option>
                        <option value="0">否</option>
                    </select>
                    </span>
                </td>
                <td>存尸日期：<span class="c-red">*</span></td>
                <td>
                    <input type="text" onfocus="WdatePicker({ dateFmt:'yyyy-MM-dd HH:mm:ss' })" id="cs_datetime" name="cs_datetime" value="{$djrq}" class="input-text Wdate radius size-S" required>
                </td>
                <td>房  间  号：<span class="c-red">*</span></td>
                <td>
                    <span class="select-box radius size-S">
                    <select name="cs_fjid" id="cs_fjid" class="select" onchange="return select_fjxx(this);" required>
                        <option value="">请选择存尸房间号</option>
                        {foreach $fjxx as $k=>$v}
                        <option value="{$v.id}">{$v.id}</option>
                        {/foreach}
                    </select>
                    </span>
                </td>
                <td>房间费用：</td>
                <td colspan="3">
                    <input type="text" name="cs_price" id="cs_price" class="input-text radius size-S" required>
                </td>
            </tr>
            <tr><td colspan="8"></td></tr>
            <tr>
                <td>是否定炉出殡：<span class="c-red">*</span></td>
                <td>
                    <span class="select-box radius size-S">
                    <select name="is_dlcb" id="is_dlcb" class="select" onchange="return isCb_Btn_onclick(this);" required>
                        <option value="">是否定炉出殡</option>
                        <option value="1">是</option>
                        <option value="0">否</option>
                    </select>
                    </span>
                </td>
                <td>出殡日期：<span class="c-red">*</span></td>
                <td>
                    <input type="text" onchange="change_select();" onfocus="WdatePicker({ dateFmt:'yyyy-MM-dd' })" id="cbrq" name="cbrq" value="{$swrq}" class="input-text Wdate  radius size-S" required>
                </td>
                <td>预  定  炉：<span class="c-red">*</span></td>
                <td>
                    <span class="select-box radius size-S">
                    <select name="ydl" id="ydl" class="select" onchange="return select_ydlcxx(this);" required>
                        <option value="">请选择火化炉</option>
                        {foreach $hhl as $k=>$v}
                        <option value="{$v.id}">{$v.title}</option>
                        {/foreach}
                    </select>
                    </span>
                </td>
                <td>预定炉次：</td>
                <td>
                    <span class="select-box radius size-S">
                    <select name="ydlc" id="ydlc" class="select" required>
                        <option value="">请选择预定炉次</option>
                    </select>
                    </span>
                </td>
            </tr>
            <tr>
                <td>出殡方式：<span class="c-red">*</span></td>
                <td>
                    <span class="select-box radius size-S">
                    <select name="cbfs" id="cbfs" class="select" onchange="return select_cbxx(this);">
                        <option value="">请选择出殡方式</option>
                        {foreach $cbfs as $k=>$v}
                        {if $v.use_date==$swrq}
                        <optgroup label="{$v.title} 使用中..."></optgroup>
                        {else}
                        <option value="{$v.title}">{$v.title}</option>
                        {/if}
                        {/foreach}
                    </select>
                    </span>
                </td>
                <td>出殡费用：<span class="c-red">*</span></td>
                <td>
                    <input type="text" id="cbfy" name="cbfy" value="" class="input-text radius size-S">
                </td>

                <td>告  别  厅：<span class="c-red"></span></td>
                <td>
                    <span class="select-box radius size-S">
                    <select name="gbt" id="gbt" class="select" onchange="return select_gbtxx(this);">
                        <option value="">请选择告别厅</option>
                        {foreach $gbt as $k=>$v}
                        <option value="{$v.title}">{$v.title}</option>
                        {/foreach}
                    </select>
                    </span>
                </td>
                <td>告别厅费用：<span class="c-red"></span></td>
                <td>
                    <input type="text" id="gbtfy" name="gbtfy" value="" class="input-text radius size-S">
                </td>

            </tr>

            </tbody>
        </table>
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input type="hidden" name="btn_type" id="btn_type" value="0">
                <!--<input class="btn btn-primary radius" type="button" name="save_print_btn" id="save_print_btn" value="&nbsp;&nbsp;保存并打印订单&nbsp;&nbsp;">-->
                &nbsp;&nbsp;&nbsp;&nbsp;
                <input class="btn btn-success radius" type="button" name="save_btn" id="save_btn" value="&nbsp;&nbsp;保存&nbsp;&nbsp;">
                &nbsp;&nbsp;&nbsp;&nbsp;
                <input class="btn btn-warning radius" type="reset" name="reset_btn" id="reset_btn" value="&nbsp;&nbsp;重置&nbsp;&nbsp;">
                <input class="btn btn-success radius" type="submit" name="tj_btn" id="tj_btn" value="&nbsp;&nbsp;保存&nbsp;&nbsp;" style="display: none;">
            </div>

        </div>
    </form>
</article>

<!--_footer 作为公共模版分离出去-->
{include file='public/_footer'}
<!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="__PUBLIC__lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="__PUBLIC__lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="__PUBLIC__lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript" src="__PUBLIC__lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript">
    $(function(){
        $('.skin-minimal input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        });
        $('#save_print_btn').click(function(){
            $('#btn_type').val('1');
            if($("#form-admin-add").valid()){
                $('#tj_btn').click();
            }
        });
        $('#save_btn').click(function(){
            $('#btn_type').val('0');
            if($("#form-admin-add").valid()){
                $('#tj_btn').click();
            }
        });

        $("#form-admin-add").validate({
            submitHandler:function(form){
                /**
                 * 成功之后的回调函数
                 * @type {{success: options.success}}
                 */
                var options = {
                    success: function (data) {
                        var dataobj =  JSON.parse(data);
                        if(parseInt(dataobj.statusCode)==200){
                            layer.msg(dataobj.message,{icon:1,time:1000});
                            setInterval("closeWindow()",1000);
                            return true;
                        }else{
                            layer.msg(dataobj.message,{icon:5,time:1000});
                            layer.close(index);
                            return false;
                        }
                    }
                };
                $(form).ajaxSubmit(options);
            }
        });


    });

    // 判断是否存尸
    function isCs_Btn_onclick(obj){
        var v = obj.value;
        if(parseInt(v)==0){
            // 存尸日期
            $('#cs_datetime').attr('disabled','disabled');
            $('#cs_datetime').removeAttr('required');
            // 房间号
            $('#cs_fjid').attr('disabled','disabled');
            $('#cs_fjid').removeAttr('required');
            // 房间费用
            $('#cs_price').attr('disabled','disabled');
            $('#cs_price').removeAttr('required');
        }
        if(parseInt(v)==1){
            // 存尸日期
            $('#cs_datetime').attr('required',true);
            $('#cs_datetime').removeAttr('disabled');
            // 房间号
            $('#cs_fjid').attr('required',true);
            $('#cs_fjid').removeAttr('disabled');
            // 房间费用
            $('#cs_price').attr('required',true);
            $('#cs_price').removeAttr('disabled');
        }
    }

    // 通过选取的房间号获取房间费用
    function select_fjxx(obj){
        var val = obj.value;
        if(val){
            $.getJSON("{:url('index/index/getfjxxbyfjid')}", { 'id': val }, function(data){
                var jsonObj = JSON.parse(data);
                if(parseInt(jsonObj['statusCode'])==200){
                    $('#cs_price').val(jsonObj['data']['cs_price']);
                }else{
                    alert(jsonObj['message'] );
                }
            });
        }else{
            $('#cs_price').val(0);
        }
    }

    // 判断是否定炉出殡
    function isCb_Btn_onclick(obj){
        var v = obj.value;
        if(parseInt(v)==0){
            // 出殡日期
            $('#cbrq').attr('disabled','disabled');
            $('#cbrq').removeAttr('required');
            // 预定炉
            $('#ydl').attr('disabled','disabled');
            $('#ydl').removeAttr('required');
            // 预定炉次
            $('#ydlc').attr('disabled','disabled');
            $('#ydlc').removeAttr('required');
            // 出殡方式
            $('#cbfs').attr('disabled','disabled');
            $('#cbfs').removeAttr('required');
            // 出殡费用
            $('#cbfy').attr('disabled','disabled');
            $('#cbfy').removeAttr('required');
        }
        if(parseInt(v)==1){
            // 出殡日期
            $('#cbrq').attr('required',true);
            $('#cbrq').removeAttr('disabled');
            // 预定炉
            $('#ydl').attr('required',true);
            $('#ydl').removeAttr('disabled');
            // 预定炉次
            $('#ydlc').attr('required',true);
            $('#ydlc').removeAttr('disabled');
            // 出殡方式
            $('#cbfs').attr('required',true);
            $('#cbfs').removeAttr('disabled');
            // 出殡费用
            $('#cbfy').attr('required',true);
            $('#cbfy').removeAttr('disabled');
        }
    }

    // 通过选取的告别厅获取告别厅费用
    function select_gbtxx(obj){
        var val = obj.value;
        if(val){
            jQuery.support.cors = true;
            $.ajax({
                url: "{:url('index/index/getgbtxxbytitle')}",
                data: {'title': val},
                cache: false,
                dataType: "json",
                type: "POST",
                success: function (json, success) {
                    var jsonObj = JSON.parse(json);
                    if(parseInt(jsonObj['statusCode'])==200){
                        $('#gbtfy').val(jsonObj['data']['price']);
                    }else{
                        alert(jsonObj['message'] );
                    }
                }
            });
        }else{
            $('#gbtfy').val(0);
        }
    }

    // 通过选取的出殡方式获取出殡费用
    function select_cbxx(obj){
        var val = obj.value;
        if(val){
            $.getJSON("{:url('index/index/getcbxxbytitle')}", { 'title': val }, function(data){
                var jsonObj = JSON.parse(data);
                if(parseInt(jsonObj['statusCode'])==200){
                    $('#cbfy').val(jsonObj['data']['price']);
                }else{
                    alert(jsonObj['message'] );
                }
            });
        }else{
            $('#cbfy').val(0);
        }
    }

    // 通过选取的预定炉获取预定炉次
    function select_ydlcxx(obj){
        var val = obj.value;
        var cbrq = $('#cbrq').val();
        if(val && cbrq){

            jQuery.support.cors = true;
            $.ajax({
                url: "{:url('index/index/getydlcxxbyid')}",
                data:{ 'id': val,'cbrq':cbrq },
                cache: false,
                dataType: "json",
                type: "POST",
                success: function(json, success) {
                    var jsonObj = JSON.parse(json);
                    if(parseInt(jsonObj['statusCode'])==200){
                        var lc = jsonObj['data']['list'];
                        var html = '';
                        html += '<option value="">请选择预定炉次</option>';
                        for(var i in lc){
                            if(lc[i]['hhllc'])	{
                                if(lc[i]['status']==1){
                                    html += "<optgroup label='" + lc[i]['hhllc'] + "&nbsp;&nbsp;使用中...'></optgroup>";
                                }else{
                                    html += "<option value='" + lc[i]['id'] + "'>" + lc[i]['hhllc'] + "</option>";
                                }
                            }
                        }
                        $('#ydlc').html(html);

                        var cb = jsonObj['cbdata']['list'];
                        var cbhtml = '';
                        cbhtml += '<option value="">请选择出殡方式</option>';
                        for(var i in cb){
                            if(cb[i]['title'])	{
                                if(cb[i]['status']==1){
                                    cbhtml += "<optgroup label='" + cb[i]['title'] + "&nbsp;&nbsp;使用中...'></optgroup>";
                                }else{
                                    cbhtml += "<option value='" + cb[i]['title'] + "'>" + cb[i]['title'] + "</option>";
                                }
                            }
                        }
                        $('#cbfs').html(cbhtml);
                    }else{
                        layer.msg(jsonObj['message'] );
                    }
                }
            });
        }else{
            if($('#cbrq').val()==''){
                $('#cbrq').focus();
            }
            $('#ydlc').html('<option value="">请选择预定炉次</option>');
        }
    }

    // 改变出殡日期后改变预定炉次信息
    function change_select(){
        var obj = document.getElementById('ydl');
        select_ydlcxx(obj);
    }


    function closeWindow(){
        var index = parent.layer.getFrameIndex(window.name);
        window.parent.location.reload();
    }


</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>